import React from 'react';
import Ay from '../../images/ay.png';
import Ays from '../../images/ays.png';
import Zc from '../../images/zc.png'
import Set from '../../images/Set.png'
import './index.less';


const date = getBeforeDate('2020,5,21');

const Account = (props) => {


	return (
		<div className={`${props.className} account-container`}>
			<img className={'img1'} src={Ay}/>
			<img className={'img2 account-turn'} src={Ays}/>
			<div className={'account-day'}>
				<div className={'account-text1'}>安全运行天数</div>
				<div className={'account-text2'}> {date}天</div>
			</div>

			<img className={'img3'} src={Zc}/>

			<div className={'account-position'}>
				<div>Test</div>
				<div>职称</div>
			</div>
			<img className={'img4 account-turn'} src={Set}/>
		</div>
	)
}

export default Account



function getBeforeDate(n){
	var now = new Date();
	var aftertime = new Date(n);
	var year = now.getFullYear();
	var mon= now.getMonth()+1;
	var day= now.getDate();
	var year_after = aftertime.getFullYear();
	var mon_after = aftertime.getMonth()+1;
	var day_after = aftertime.getDate();
	var chs = 0;
	//获取当月的天数
	function DayNumOfMonth(Year,Month)
	{
		return 32 - new Date(Year,Month-1,32).getDate();
	}
	if(aftertime.getTime() - now.getTime() < 0){
		var temp1 = day_after;
		var temp2 = mon_after;
		var temp3 = year_after;
		day_after = day;
		mon_after = mon;
		year_after = year;
		day = temp1;
		mon = temp2;
		year = temp3;
	}
	if(year == year_after){//不跨年
		if(mon == mon_after){//不跨年不跨月
			chs += day_after-day;
		}else{//不跨年跨月
			chs += DayNumOfMonth(year,mon)- day+1;//加上第一个不满的
			for(var i=1;i< mon_after-mon;i++){
				chs += DayNumOfMonth(year,mon+i);
			}
			chs += day_after-1;//加上
		}
	}else{//存在跨年
		chs += DayNumOfMonth(year,mon)- day+1;//加上开始年份不满的一个月
		for(var m=1;m<12-mon;m++){
			chs += DayNumOfMonth(year,mon+m);
		}
		for(var j=1;j < year_after-year;j++){
			if((year+j)%400 == 0 || (year+j)%4 == 0 && (year+j)%100 != 0){
				chs += 366;
			}else{
				chs += 365;
			}
		}
		for(var n=1;n <= mon_after;n++){
			chs += DayNumOfMonth(year_after,n);
		}
		chs += day_after-1;
	}

		return chs;

}